package com.itheima.reggie.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * @author Yan
 * @date 2022/2/27
 * 用于复制文件
 */
public class CopyFile {


    public static void copy(String fileName) throws Exception {
        String path = "D:\\Develop\\myfile\\";
        String tar = "D:\\Develop\\myfile\\save\\";
        File file =new File(path+fileName);
        FileInputStream fileInputStream =new FileInputStream(file);

        FileOutputStream fileOutputStream = new FileOutputStream(tar+fileName);

        int len;
        byte[] bytes =new byte[1024];
        while ((len =fileInputStream.read(bytes))!=-1){
            fileOutputStream.write(bytes,0,len);
            fileOutputStream.flush();
        }

        fileOutputStream.close();
        fileInputStream.close();
    }

}
